// sections/sections.cpp
// Written by, Sohail Qayum Malik[sqm@cyberian.pk]

/* For debuging purposes, should be gone when done */
//#include <iostream>
/*  For debugging purposes ends here */

#include "sections.h"

int sections(char const*const*const argv, arg_history common_arg, arg_history dosheader_arg) throw(args_exception) {

   int ret = 0;

   try {
   
      argument<arg_history>::pointer ptr = argument<arg_history>::NewE(dosheader_arg.get_argc(), argv + dosheader_arg.get_index() , COMMANDS);
      argument<arg_history>::iterator itB(ptr->begin());

      for ( int i = 1; i < common_arg.get_argc(); i++ ) {	  
	  
	      ret = parser((argv + common_arg.get_index())[i], callback_sections, PARSER_IMAGE_SECTION_HEADERS);
      }

      for ( int i = 1; i < itB[COMMON].get_argc(); i++) { 

          ret = parser((argv + dosheader_arg.get_index() + itB[COMMON].get_index())[i], callback_sections, PARSER_IMAGE_SECTION_HEADERS);
	  }
   }
   catch(args_exception &e) {
   
      throw(e);   
   }
    
   return ret;
}